﻿using DetectScars.model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DetectScars.Menus
{
    public partial class LoadForm : Form
    {
        public LoadForm()
        {
            InitializeComponent();
        }
        List<Dac> Dacs;
        Dac curr_dac;
        internal LoadForm(List<Dac> dacs)
        {
            InitializeComponent();
            Dacs = dacs;
        }
        internal Dac GetDac()
        {
            return curr_dac;
        }

        private void LoadForm_Load(object sender, EventArgs e)
        {
            comboBox1.Items.Clear();
            foreach (Dac dac in Dacs)
            {
                comboBox1.Items.Add(dac);
            }
            comboBox1.ValueMember = "Name";
            comboBox1.SelectedIndex = 0;

        }

        private void comboBox1_TextChanged(object sender, EventArgs e)
        {
            curr_dac = comboBox1.SelectedItem as Dac;
            if (curr_dac != null)
            {
                table1.Controls.Clear();
                //赋值
                string[] row1 = curr_dac.tof_s.Split(",");
                string[] row2 = curr_dac.gains.Split(",");
                table1.RowCount = 2;
                table1.ColumnCount = row1.Length;
                for (int col = 0; col < row1.Length; col++)
                {

                    TextBox textBox1 = new TextBox
                    {
                        Dock = DockStyle.Fill,
                        Text = row1[col],
                        TextAlign = System.Windows.Forms.HorizontalAlignment.Center
                    };
                    TextBox textBox2 = new TextBox
                    {
                        Dock = DockStyle.Fill,
                        Text = row2[col],
                        TextAlign = System.Windows.Forms.HorizontalAlignment.Center
                    };
                    table1.Controls.Add(textBox1, col, 0);
                    table1.Controls.Add(textBox2, col, 1);
                    table1.ColumnStyles[col].Width = 50;
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
        }
    }
}
